import { defineStore } from "pinia";
import { reqC1, reqC2, reqC3 } from "@/api/product/attribute";
import type { CategoryResponseData } from '@/api/product/attribute/type'
import type { CategoryState } from './type/type'
const useCategoryStore = defineStore('Category', {
    state: (): CategoryState => {
        return {
            c1Arr: [],
            c1Id: '',
            c2Arr: [],
            c2Id: '',
            c3Arr: [],
            c3Id: '',
        }
    },
    actions: {
        async getC1() {
            const res: CategoryResponseData = await reqC1()
            console.log(res, '一级分类数据')
            if (res.code == 0) {
                this.c1Arr = res.data
            }
        },

        async getC2() {
            const res: CategoryResponseData = await reqC2(this.c1Id)
            console.log(res, '二级分类数据')
            if (res.code == 0) {
                this.c2Arr = res.data
            }
        },

        async getC3() {
            const res: CategoryResponseData = await reqC3(this.c2Id)
            if (res.code == 0) {
                this.c3Arr = res.data
            }
        },

    },
    getters: {}
})

export default useCategoryStore